package com.yurui.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyHandler implements InvocationHandler {

    private Object target;

    private LogAdvice logAdvice;

    public MyHandler(Object target,LogAdvice logAdvice) {
        this.target = target;
        this.logAdvice = logAdvice;
    }

    public Object getTarget() {
        return target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        logAdvice.before();
//        System.out.println("method:"+method);
        System.out.println("args:"+args);
        Object result = method.invoke(target, args);
        System.out.println("result:"+result);
        logAdvice.after();
        return result;
    }
}
